package com.bqtv.sport.ui.match

import android.content.Context
import android.content.Intent
import android.view.KeyEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bqtv.sport.R
import com.bqtv.sport.adapter.HomeHotAdapter
import com.bqtv.sport.adapter.MatchDateMonthAdapter
import com.bqtv.sport.adapter.MatchDateWeekAdapter
import com.bqtv.sport.adapter.SearchHotAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.commen.utils.DpUtil
import com.bqtv.sport.commen.widget.GridItemDecoration
import com.bqtv.sport.databinding.ActivityMatchDateBinding
import com.bqtv.sport.databinding.ActivityMatchSettingBinding
import com.bqtv.sport.databinding.ActivitySearchBinding
import com.bqtv.sport.databinding.ItemMatchDateWeekBinding
import com.gyf.immersionbar.ImmersionBar
import com.hjq.base.BaseActivity
import com.library.flowlayout.FlowLayoutManager
import com.library.flowlayout.SpaceItemDecoration

class MatchDateActivity : AppActivity<ActivityMatchDateBinding>() {
    private lateinit var weekAdapter: MatchDateWeekAdapter
    private lateinit var monthAdapter: MatchDateMonthAdapter
    companion object {
        private const val INTEXT_KEY_CONTENT = "content"
        fun start(activity: BaseActivity, listener: OnScanListener?) {
            val intent = Intent(activity, MatchDateActivity::class.java)
            activity.startActivityForResult(
                intent,
                object : BaseActivity.OnActivityCallback {
                    override fun onActivityResult(resultCode: Int, data: Intent?) {
                        if (listener == null || data == null) {
                            return
                        }
                        if (resultCode == RESULT_OK) {
                            val content =
                                data.getStringExtra(INTEXT_KEY_CONTENT)
                            listener.onSucceed(content)
                        } else {
                            listener.onCancel()
                        }
                    }
                })
        }
    }

    override fun getViewBinding() = ActivityMatchDateBinding.inflate(layoutInflater)

    override fun initView() {
        ImmersionBar.setTitleBarMarginTop(this, binding.rlTitle)
        binding.rcvWeek.layoutManager = GridLayoutManager(this, 7)
        binding.rcvMonth.layoutManager = GridLayoutManager(this, 7)
        weekAdapter= MatchDateWeekAdapter()
        binding.rcvWeek.adapter = weekAdapter

        binding.rcvMonth.addItemDecoration(
            GridItemDecoration(
            getContext(), 7,
            GridItemDecoration.LineDrawMode.HORIZONTAL, 1, 12
        ))
        monthAdapter= MatchDateMonthAdapter()
        binding.rcvMonth.adapter = monthAdapter

    }

    override fun initData() {
        var list = arrayListOf<String>("日", "一", "二", "三", "四", "五", "六")
        weekAdapter.submitList(list)

        initListener()
    }

    private fun initListener() {
        binding.ivBack.setOnClickListener {
            finish()
        }
        binding.tvConfirm.setOnClickListener {

            finish()
        }
        binding.tdLastMonth.setOnClickListener {

        }
        binding.tdNextMonth.setOnClickListener {

        }
        monthAdapter.setOnItemClickListener { adapter, view, position ->
            monthAdapter.check = position
            monthAdapter.notifyDataSetChanged()
        }
    }

    override fun onClick(view: View) {
        super.onClick(view)

    }

    interface OnScanListener {
        /**
         * 成功
         */
        fun onSucceed(content: String?)

        /**
         * 取消
         */
        fun onCancel() {}
    }
}